<!DOCTYPE html>
<!--
Copyright 2012 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<html>
<head>
<title>
  NativeClient browser test runner
</title>
<script type="text/javascript" src="nacltest.js"></script>
<script type="text/javascript" src="nmf_test_list.js"></script>
</head>
<body>

<div id="scratch_space"></div>

<div id="load_warning">
Javascript has failed to load.
</div>

<script type="text/javascript">

function addTest(tester, url) {
  tester.addAsyncTest(url, function(status) {
    var embed = document.createElement('embed');
    embed.width = 0;
    embed.height = 0;
    embed.src = url;
    embed.type = 'application/x-nacl';
    embed.name = 'foo';

    // Webkit Bug Workaround
    // THIS SHOULD BE REMOVED WHEN Webkit IS FIXED
    // http://code.google.com/p/nativeclient/issues/detail?id=2428
    // http://code.google.com/p/chromium/issues/detail?id=103588
    ForcePluginLoadOnTimeout(embed, tester, 15000);

    var div = document.createElement('div');
    div.appendChild(embed);

    var cleanup = function() {
      document.getElementById('scratch_space').removeChild(div);
    };

    // Set up an event listener for success messages.
    div.addEventListener('message', status.wrap(function(message_event) {
      status.assertEqual(message_event.data, 'passed');
      cleanup();
      status.pass();
    }), true);

    // Wait for the load event, which indicates successful loading.
    div.addEventListener('load', status.wrap(function(e) {
      status.log('Loaded ' + embed.src);
      // Start tests in the module.
      embed.postMessage('run_tests');
    }), true);

    var onError = status.wrap(function(e) {
      cleanup();
      status.fail(embed.lastError);
    });

    div.addEventListener('error', onError, true);
    div.addEventListener('crash', onError, true);

    // Insert div into the DOM.  This starts the load of the nacl plugin, etc.
    document.getElementById('scratch_space').appendChild(div);
  });
}

// Remove the "failed to load" message.
document.getElementById('load_warning').innerHTML = '';

var tester = new Tester();
for (var i = 0; i < G_NMF_TEST_LIST.length; i++) {
  addTest(tester, G_NMF_TEST_LIST[i]);
}

var args = getTestArguments({'parallel': '0'});

if (parseInt(args['parallel'])) {
  tester.runParallel();
} else {
  tester.run();
}

</script>
</body>
</html>
